package com.linksfield.topup.controller.commonmanage;

import com.alibaba.fastjson.JSON;
import com.linksfield.topup.config.dto.ResultDataDto;
import com.linksfield.topup.config.dto.StringOutputConstant;
import com.linksfield.topup.entity.interfaces.planmanage.partnernamelist.request.RequestPartnerNameList;
import com.linksfield.topup.entity.interfaces.planmanage.partnernamelist.response.ResponsePartnerNameList;
import com.linksfield.topup.service.ServicePlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公用接口管理控制器类
 *
 * @author: lm
 * @date: 2020-07-15 16:30
 */
@RestController
@Api(value = "公用接口管理")

public class CommonManageController {

    @Autowired
    ServicePlanService planService;

    private static Logger logger = Logger.getLogger(CommonManageController.class);

    @PostMapping(value = "partnerNameList", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "除新建套餐选择企业之外的所有：【获取企业名称列表】", response = ResponsePartnerNameList.class)
    public ResultDataDto partnerNameList(@ApiParam @RequestBody RequestPartnerNameList request,
                                         @RequestHeader(name = "x-access-token", required = false) String token) {
        logger.info("【除新建套餐选择企业之外的所有：【获取企业名称列表】】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return planService.partnerNameList(request, token);
    }

}
